﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using App.Domain.Model;
using App.Service.WebAPI.Resources;
using System.Collections.Specialized;
using App.Composers;
using System.Web;

namespace App.Service.WebAPI.Controllers
{
    public class AddressController : ControllerBase
    {
        public IEnumerable<Address> GET()
        {
            int ownerId;
            Int32.TryParse(QueryString["domainId"], out ownerId);
            var addressBoList = bal.GetAddresses(QueryString["type"], ownerId);
            //AddressCollection result = new AddressCollection();
            //result.AddRange(addressBoList.Select(adbo => new AddressDTO(adbo)));

            //addressColection.AddSelfLink(Request.RequestUri.AbsoluteUri);
            //if (addressColection.Items != null && addressColection.Items.Count() > 0)
            //{
            //    addressColection.AddFirstLink(RequestUri + "/" + addressColection.Items.FirstOrDefault().ID + "." + UriExtension);
            //    addressColection.AddLastLink(RequestUri + "/" + addressColection.Items.LastOrDefault().ID + "." + UriExtension);
            //}
            return addressBoList;
        }
        public Address GET(string secondLevel)
        {
            int idint;
            if (Int32.TryParse(secondLevel, out idint))
            {
                return bal.GetAddress(idint);
                //return new AddressDTO(bal.GetAddress(idint));
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
    }
}